package szwolaiyun.paireach.com.szwolaizhuang.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.paireach.szwolaiyun.sz_common_widget.activity.BaseActivity;
import com.paireach.szwolaiyun.sz_util.SharedPreferencesUtil;

import szwolaiyun.paireach.com.szwolaizhuang.R;
import szwolaiyun.paireach.com.szwolaizhuang.model.event.HttpErrorEvent;
import szwolaiyun.paireach.com.szwolaizhuang.model.event.HttpSuccessEvent;
import szwolaiyun.paireach.com.szwolaizhuang.model.requestTag.RequestTag;
import szwolaiyun.paireach.com.szwolaizhuang.net.UserRequest;

public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener {

    Button button;
    EditText et1, et2;
    ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_password);
        et1 = (EditText) findViewById(R.id.et1);
        et2 = (EditText) findViewById(R.id.et2);
        button = (Button) findViewById(R.id.buttonPanel);
        button.setOnClickListener(this);
        iv = (ImageView) findViewById(R.id.layout_top_back);
        iv.setOnClickListener(this);
        ((TextView) findViewById(R.id.layout_top_change)).setText("设置密码");
    }

    @Override
    public void onClick(View view) {
        if (view == button) {
            String pass1 = et1.getText().toString();
            String pass2 = et2.getText().toString();
            if (TextUtils.isEmpty(pass1) || TextUtils.isEmpty(pass2)) {
                showToast("密码不能为空");
            } else if (!pass1.equals(pass2)) {
                showToast("两次输入的密码不一致");
            } else {
//                showProgressDialog();
//                new UserRequest().changePassword(SharedPreferencesUtil.getValue(this,SharedPreferencesUtil.USER_PHONE), pass1);
                showToast("无接口调用");
            }
        } else if (view == iv) {
            finish();
        }
    }

    @Override
    public void httpErrorEvent(HttpErrorEvent event) {
        super.httpErrorEvent(event);
        if (event.getRequestTag() == RequestTag.CHANGE_PASSWORD) {
            dismissProgressDialog();
            showToast(event.getErrorMessage());
        }
    }

    @Override
    public void httpSuccessEvent(HttpSuccessEvent event) {
        super.httpSuccessEvent(event);
        if (event.getRequestTag() == RequestTag.CHANGE_PASSWORD) {
            dismissProgressDialog();
            if (event.getJson().equals("0")) {
                showToast("密码修改失败");
            } else {
                showToast("密码修改成功");
                finish();
            }
        }
    }
}
